/* -*- C++ -*- */
/**
*  @file Supplier.h
*
*  $Id: Supplier.h 77020 2007-02-12 13:56:49Z johnnyw $
*
*  @author Pradeep Gore <pradeep@oomworks.com>
*
*
*/

#ifndef TAO_Notify_SUPPLIER_H
#define TAO_Notify_SUPPLIER_H
#include /**/ "ace/pre.h"

#include "dllmain.h"
#include <ace/Condition_Thread_Mutex.h>
#include <tao/RTCORBA/RTCORBA.h>
#include <orbsvcs/CosNotifyChannelAdminS.h>
#include <orbsvcs/CosNotifyCommC.h>
#include "orbsvcs/NotifyExtC.h"
#include <vector>
#include <boost/shared_ptr.hpp>

/**
* @class ORB_Notify_Supplier
*
* @brief Implement a Structured Supplier.
*
*/
class CPPXCORBA_API ORB_Notify_Supplier : public POA_CosNotifyComm::StructuredPushSupplier
{
public:
    // = Initialization and Termination code

    /// Constructor.
    ORB_Notify_Supplier (void);

    /// Destructor
    virtual ~ORB_Notify_Supplier();

    /// Init
    void init_supplier(
        CosNotifyChannelAdmin::SupplierAdmin_var& admin,
        int proxy_consumer_thread_count = 0);

    /// Send one event.
    void send_event (const CosNotification::StructuredEvent& event);

    // = Protected Methods
protected:
    /// Connect the Supplier to the EventChannel.
    /// Creates a new proxy consumer and connects to it.
    void connect (void);

    /// Disconnect the supplier.
    void disconnect (void);

    /// Deactivate.
    void deactivate (void);

    ///= NotifySubscribe method
protected:
    virtual void subscription_change (
        const CosNotification::EventTypeSeq & added,
        const CosNotification::EventTypeSeq & removed);

    ///= StructuredPushSupplier method
protected:
    virtual void disconnect_structured_push_supplier (void);

    ///= Data members
protected:
    /// The proxy that we are connected to.
    CosNotifyChannelAdmin::StructuredProxyPushConsumer_var proxy_consumer_;

    /// This supplier's id.
    CosNotifyChannelAdmin::ProxyID proxy_consumer_id_;

    // The Supplier Admin
    CosNotifyChannelAdmin::SupplierAdmin_var admin_;

    /// Lock to serialize internal state.
    TAO_SYNCH_MUTEX lock_;

    /// Number of Threads at the ProxyConsumer.
    int proxy_consumer_thread_count_;
};

typedef boost::shared_ptr<ORB_Notify_Supplier> supplier_ptr;

#include /**/ "ace/post.h"
#endif /* TAO_Notify_SUPPLIER_H */
